package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Override
    public UserInfo login(UserInfo userInfo) {

        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("login_name",userInfo.getLoginName());
        String newPasswd = DigestUtils.md5DigestAsHex(userInfo.getPasswd().getBytes());
        queryWrapper.eq("passwd",newPasswd);
        return userInfoMapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserAddress> findUserAddressListByUserId(String userId) {
        return userAddressMapper.selectList(new QueryWrapper<UserAddress>().eq("user_id",userId));
    }

    @Autowired
    private UserAddressMapper userAddressMapper;

    public static void main(String[] args) {
        String s = DigestUtils.md5DigestAsHex("123".getBytes());
        System.out.println(s);
    }
}
